﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Code;
using System.Data;

namespace E2_WEBSITE
{
    public class Basket
    {
        protected static Basket m_Basket;
        protected static BasketController m_BasketController;

        public static Basket GlobalBasket
        {
            get {
                if (m_Basket == null)
                {
                    m_Basket = new Basket();
                    if (m_BasketController == null)
                    {
                        m_BasketController = new BasketController();
                    }
                }
                return Basket.m_Basket; 
            }
            set { Basket.m_Basket = value; }
        }

        protected Basket()
        {
        }

        // get the lastest basket of member
        public int getCurrentBasketID(int memID)
        {
            return m_BasketController.getCurrentBasketID(memID);
        }

        // add product with id and quantity to basket of a customer
        public void addToBasket(int basketID, int productID, int colorID, int quantity)
        {
            m_BasketController.addToBasket(basketID, productID, colorID, quantity);
        }

        // remove product from a basket of a customer
        public void removeFromBasket(int bID, int bdID)
        {
            m_BasketController.removeFromBasket(bID, bdID);
        }

        public DataTable getListBasket(int memID)
        {
            return m_BasketController.getListBasket(memID);
        }

        public DataTable getBasketDetail(int bID)
        {
            return m_BasketController.getBasketDetail(bID);
        }

        public void setCurrentBasketID(int bID)
        {
            m_BasketController.setCurrentBasketID(bID);
        }

        public void addNewBasket(int memID)
        {
            m_BasketController.addNewBasket(memID);
        }

        public void updatePrice(int bID)
        {
            m_BasketController.updatePrice(bID);
        }

        public void deleteBasket(int bID, int memID)
        {
            m_BasketController.deleteBasket(bID, memID);
        }

        public void updateProductQuan(int bdID, int quan)
        {
            m_BasketController.updateProductQuan(bdID, quan);
        }

        public int getMaxQuantity(int imgID)
        {
            return m_BasketController.getMaxQuantity(imgID);
        }

        public bool checkAllPriceUpdated(int bID)
        {
            return m_BasketController.checkAllPriceUpdated(bID);
        }

        public bool checkAppropriateQuantity(int bID)
        {
            return m_BasketController.checkAppropriateQuantity(bID);
        }

        public bool checkBasketEmpty(int bID)
        {
            return m_BasketController.checkBasketEmpty(bID);
        }

        public bool checkValidBasket(int mID, int bID)
        {
            return m_BasketController.checkValidBasket(mID, bID);
        }

        public int getTotalPrice(int bID)
        {
            return m_BasketController.getTotalPrice(bID);
        }

        public DataTable getPTTT()
        {
            return m_BasketController.getPTTT();
        }

        public DataTable getPTGH()
        {
            return m_BasketController.getPTGH();
        }

        public DataTable getBank()
        {
            return m_BasketController.getBank();
        }

        public int payBasket(
            int memID, 
            int basketID, 
            int totalPrice, 
            int ptgh, 
            int pttt, 
            string sTenNguoiNhan, 
            string sDiaChiNguoiNhan, 
            string sSoDTNguoiNhan, 
            string sSoTaiKhoanCongTy,
            string sTenNganHang)
        {
            return m_BasketController.payBasket(
                memID,
                basketID,
                totalPrice,
                ptgh,
                pttt,
                sTenNguoiNhan,
                sDiaChiNguoiNhan,
                sSoDTNguoiNhan,
                sSoTaiKhoanCongTy,
                sTenNganHang);
        }

        public DataTable getOrderDetail(int oID)
        {
            return m_BasketController.getOrderDetail(oID);
        }

        public void getOrderInfo(int oID, out string sHoTenNguoiNhan, out string sDiaChiNguoiNhan, out string sSoDTNguoiNhan, out string sTongTien, out string sNgayGiaoDich)
        {
            m_BasketController.getOrderInfo(oID, out sHoTenNguoiNhan, out sDiaChiNguoiNhan, out sSoDTNguoiNhan, out sTongTien, out sNgayGiaoDich);
        }
    }
}